<template>
    <div class="bigbox">
        <van-form @submit="onSubmit">
            <van-cell-group inset>
                <van-field v-model="obj.names" name="用户名" label="用户名" placeholder="用户名"
                    :rules="[{ required: true, message: '请填写用户名' }]" />
                <van-field v-model="obj.pass" type="password" name="密码" label="密码" placeholder="密码"
                    :rules="[{ required: true, message: '请填写密码' }]" />
            </van-cell-group>
            <van-radio-group v-model="obj.position">
                <van-field label="职务" />
                <van-radio name=0>项目负责人</van-radio>
                <van-radio name=1>部门经理</van-radio>
                <van-radio name=2>高级管理</van-radio>
            </van-radio-group>
            <van-radio-group v-model="obj.department">
                <van-field label="部门" />
                <van-radio name=1>数据一部</van-radio>
                <van-radio name=2>数据二部</van-radio>
                <van-radio name=3>数据三部</van-radio>
                <van-radio name=4>数据四部</van-radio>
                <van-radio name=5>数据五部</van-radio>
                <van-radio name=6>办公室</van-radio>
                <van-radio name=7>其他</van-radio>
            </van-radio-group>
            <van-radio-group v-model="obj.permissionId">
                <van-field label="权限" />
                <van-radio name=1>数据一部</van-radio>
                <van-radio name=2>数据二部</van-radio>
                <van-radio name=3>数据三部</van-radio>
                <van-radio name=4>数据四部</van-radio>
                <van-radio name=5>数据五部</van-radio>
                <van-radio name=6>办公室</van-radio>
            </van-radio-group>
            <div style="margin: 16px;">
                <van-button round block type="primary" native-type="submit">
                    添加
                </van-button>
            </div>
        </van-form>

    </div>
</template>

<script setup>
import { onMounted, ref, watch } from 'vue'
import router from "@/router";
import { useRouter } from "vue-router";
import { addusers } from '../../sevce/user'
import { showToast } from 'vant';
import { showNotify } from 'vant';
function gohome() {
    router.push('/home')
}
///users/users_ins_api?names=哈哈哈&pass=123456&department=1&position=1&telephone=1&permissionId=1
//添加用户/users/users_ins_api?names=哈哈哈&pass=123456&department=1&position=1&telephone=1&permissionId=1
const obj = ref({
    names: '',
    pass: '',
    department: 10,
    position: 10,
    telephone: 1,
    permissionId: 10,
})
const username = ref('');
const password = ref('');
const onSubmit = (values) => {
    // console.log('submit', values);
    // console.log('obj', obj.value);
    if (obj.value.names != '' && obj.value.pass != '' && obj.value.department != 10 && obj.value.position != 10 && obj.value.permissionId != 10) {
        addusers(obj.value).then((res) => {
            if (res.data == 1) {
                showToast('添加成功');
            } else {
                showToast('添加失败');
            }

        })
    } else {
        showNotify({ type: 'danger', message: '信息不完整' });
    }

};

const zw = ref('0');
const bm = ref('0');
const qx = ref('0');
</script>

<style lang="scss" scoped>
.bigbox {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 90vh;
    overflow-y: scroll;
    padding: 30px;
}
</style>